"""
要求：
如果用户已经输入过用户名，则问候，否则要求输入用户名
"""

import json

from PythonNote.JsonNote.JsonDump import filename


def get_stored_username():
    """如果存在用户输入，则读取"""
    filename = "username.json"
    try:
        with open(filename) as f:
            username = json.load(f)
    except FileNotFoundError:
        return None
    else:
        return username

def get_new_username():
    """如果不存在用户输入，则提醒用户输入"""
    username = input("What is your name: ")
    filename = "username.json"
    with open(filename, 'w') as f:
        json.dump(username, f)
    return username

def greet_user():
    if get_stored_username():
        username = get_stored_username()
        print(f"Welcome come back {username}")
    else:
        username = get_new_username()
        print(f"I will remember you when you come back, {username}.")

greet_user()